package GUITOOl;


import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.border.LineBorder;


/**
 * The type My line border.
 *
 * @author wyc, zry
 * @version 1.0
 */
public class MyLineBorder extends LineBorder{


    private static final long serialVersionUID = 1L;

    /**
     * Instantiates a new My line border.
     *
     * @param color          the color
     * @param thickness      the thickness
     * @param roundedCorners the rounded corners
     */
    public MyLineBorder(Color color, int thickness, boolean roundedCorners) {
        super(color, thickness, roundedCorners);
    }


    /**
     * To paint th border.
     * @param c component
     * @param g image
     * @param x x
     * @param y y
     * @param width width
     * @param height height
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        Color oldColor = g.getColor();
        Graphics2D g2 = (Graphics2D)g;
        int i;
        g2.setRenderingHints(rh);
        g2.setColor(lineColor);
        for(i = 0; i < thickness; i++)  {
            if(!roundedCorners)
                g2.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
            else
                g2.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, 10, 10); //就是这一句 ，后两个参数控制圆角的大小
        }
        g2.setColor(oldColor);
    }
}